package com.liuzh.deviceinfo.view.togglebuttongroup;

import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewGroup.MarginLayoutParams;
import java.util.ArrayList;
import java.util.List;

public class FlowLayout extends ViewGroup {
    public boolean a = true;
    public int b = 0;
    public int c = -65538;
    public float d = 0.0f;
    public float e = 0.0f;
    public boolean f = false;
    public List<Float> g = new ArrayList();
    public List<Integer> h = new ArrayList();
    public List<Integer> i = new ArrayList();

    /* JADX WARNING: Missing exception handler attribute for start block: B:16:0x006a */
    /* JADX WARNING: Missing exception handler attribute for start block: B:6:0x0043 */
    /* JADX WARNING: Missing exception handler attribute for start block: B:11:0x0056 */
    /* JADX WARNING: Exception block dominator not found, dom blocks: [] */
    /* JADX WARNING: Exception block dominator not found, dom blocks: [] */
    /* JADX WARNING: Failed to process nested try/catch */
    public FlowLayout(android.content.Context r6, android.util.AttributeSet r7) {
        /*
        r5 = this;
        r5.<init>(r6, r7);
        r0 = 1;
        r5.a = r0;
        r1 = 0;
        r5.b = r1;
        r2 = -65538; // 0xfffffffffffefffe float:NaN double:NaN;
        r5.c = r2;
        r3 = 0;
        r5.d = r3;
        r5.e = r3;
        r5.f = r1;
        r4 = new java.util.ArrayList;
        r4.<init>();
        r5.g = r4;
        r4 = new java.util.ArrayList;
        r4.<init>();
        r5.h = r4;
        r4 = new java.util.ArrayList;
        r4.<init>();
        r5.i = r4;
        r6 = r6.getTheme();
        r4 = c.h.a.q.b;
        r6 = r6.obtainStyledAttributes(r7, r4, r1, r1);
        r7 = 4;
        r7 = r6.getBoolean(r7, r0);	 Catch:{ all -> 0x007f }
        r5.a = r7;	 Catch:{ all -> 0x007f }
        r7 = 2;
        r0 = r6.getInt(r7, r1);	 Catch:{ NumberFormatException -> 0x0043 }
        r5.b = r0;	 Catch:{ NumberFormatException -> 0x0043 }
        goto L_0x004e;
    L_0x0043:
        r0 = r5.a(r3);	 Catch:{ all -> 0x007f }
        r0 = (int) r0;	 Catch:{ all -> 0x007f }
        r7 = r6.getDimensionPixelSize(r7, r0);	 Catch:{ all -> 0x007f }
        r5.b = r7;	 Catch:{ all -> 0x007f }
    L_0x004e:
        r7 = 3;
        r0 = r6.getInt(r7, r2);	 Catch:{ NumberFormatException -> 0x0056 }
        r5.c = r0;	 Catch:{ NumberFormatException -> 0x0056 }
        goto L_0x0061;
    L_0x0056:
        r0 = r5.a(r3);	 Catch:{ all -> 0x007f }
        r0 = (int) r0;	 Catch:{ all -> 0x007f }
        r7 = r6.getDimensionPixelSize(r7, r0);	 Catch:{ all -> 0x007f }
        r5.c = r7;	 Catch:{ all -> 0x007f }
    L_0x0061:
        r7 = 5;
        r0 = r6.getInt(r7, r1);	 Catch:{ NumberFormatException -> 0x006a }
        r0 = (float) r0;	 Catch:{ NumberFormatException -> 0x006a }
        r5.d = r0;	 Catch:{ NumberFormatException -> 0x006a }
        goto L_0x0074;
    L_0x006a:
        r0 = r5.a(r3);	 Catch:{ all -> 0x007f }
        r7 = r6.getDimension(r7, r0);	 Catch:{ all -> 0x007f }
        r5.d = r7;	 Catch:{ all -> 0x007f }
    L_0x0074:
        r7 = 6;
        r7 = r6.getBoolean(r7, r1);	 Catch:{ all -> 0x007f }
        r5.f = r7;	 Catch:{ all -> 0x007f }
        r6.recycle();
        return;
    L_0x007f:
        r7 = move-exception;
        r6.recycle();
        throw r7;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.liuzh.deviceinfo.view.togglebuttongroup.FlowLayout.m4640init(android.content.Context, android.util.AttributeSet):void");
    }

    public final float a(float f) {
        return TypedValue.applyDimension(1, f, getResources().getDisplayMetrics());
    }

    public final float b(int i, int i2, int i3, int i4) {
        if (i == -65536) {
            return i4 > 1 ? (float) ((i2 - i3) / (i4 - 1)) : 0.0f;
        } else {
            return (float) i;
        }
    }

    public final int c(int i, int i2) {
        return i > i2 ? i : i2;
    }

    public LayoutParams generateLayoutParams(LayoutParams layoutParams) {
        return new MarginLayoutParams(layoutParams);
    }

    public int getChildSpacing() {
        return this.b;
    }

    public int getChildSpacingForLastRow() {
        return this.c;
    }

    public float getRowSpacing() {
        return this.d;
    }

    public void onLayout(boolean z, int i, int i2, int i3, int i4) {
        int paddingLeft = getPaddingLeft();
        int paddingRight = getPaddingRight();
        int paddingTop = getPaddingTop();
        int width = this.f ? getWidth() - paddingRight : paddingLeft;
        int size = this.i.size();
        int i5 = 0;
        int i6 = 0;
        while (i5 < size) {
            int intValue = ((Integer) this.i.get(i5)).intValue();
            int intValue2 = ((Integer) this.h.get(i5)).intValue();
            float floatValue = ((Float) this.g.get(i5)).floatValue();
            int i7 = 0;
            while (i7 < intValue && i6 < getChildCount()) {
                int i8 = i6 + 1;
                View childAt = getChildAt(i6);
                if (childAt.getVisibility() != 8) {
                    int i9;
                    int i10;
                    int i11;
                    i7++;
                    LayoutParams layoutParams = childAt.getLayoutParams();
                    if (layoutParams instanceof MarginLayoutParams) {
                        MarginLayoutParams marginLayoutParams = (MarginLayoutParams) layoutParams;
                        i9 = marginLayoutParams.leftMargin;
                        i10 = marginLayoutParams.rightMargin;
                        i11 = marginLayoutParams.topMargin;
                        i = paddingLeft;
                    } else {
                        i = paddingLeft;
                        i10 = 0;
                        i11 = 0;
                        i9 = 0;
                    }
                    paddingLeft = childAt.getMeasuredWidth();
                    int measuredHeight = childAt.getMeasuredHeight();
                    i2 = size;
                    if (this.f) {
                        size = width - i10;
                        i3 = intValue;
                        i11 += paddingTop;
                        i4 = i7;
                        childAt.layout(size - paddingLeft, i11, size, i11 + measuredHeight);
                        paddingLeft = (int) (((float) width) - (((((float) paddingLeft) + floatValue) + ((float) i9)) + ((float) i10)));
                    } else {
                        i3 = intValue;
                        i4 = i7;
                        size = width + i9;
                        i11 += paddingTop;
                        childAt.layout(size, i11, size + paddingLeft, i11 + measuredHeight);
                        paddingLeft = (int) ((((((float) paddingLeft) + floatValue) + ((float) i9)) + ((float) i10)) + ((float) width));
                    }
                    width = paddingLeft;
                    paddingLeft = i;
                    size = i2;
                    intValue = i3;
                    i7 = i4;
                }
                i6 = i8;
            }
            i = paddingLeft;
            i2 = size;
            width = this.f ? getWidth() - paddingRight : i;
            paddingTop = (int) ((((float) intValue2) + this.e) + ((float) paddingTop));
            i5++;
            paddingLeft = i;
            size = i2;
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:66:0x0218  */
    /* JADX WARNING: Removed duplicated region for block: B:65:0x0216  */
    /* JADX WARNING: Removed duplicated region for block: B:70:0x021f  */
    /* JADX WARNING: Removed duplicated region for block: B:69:0x021d  */
    /* JADX WARNING: Removed duplicated region for block: B:59:0x01ff  */
    /* JADX WARNING: Removed duplicated region for block: B:54:0x01ee  */
    /* JADX WARNING: Removed duplicated region for block: B:65:0x0216  */
    /* JADX WARNING: Removed duplicated region for block: B:66:0x0218  */
    /* JADX WARNING: Removed duplicated region for block: B:69:0x021d  */
    /* JADX WARNING: Removed duplicated region for block: B:70:0x021f  */
    /* JADX WARNING: Missing block: B:46:0x01ca, code skipped:
            if (r0 < r1) goto L_0x01ce;
     */
    /* JADX WARNING: Missing block: B:61:0x020e, code skipped:
            if (r2 < r3) goto L_0x0212;
     */
    public void onMeasure(int r26, int r27) {
        /*
        r25 = this;
        r6 = r25;
        super.onMeasure(r26, r27);
        r7 = android.view.View.MeasureSpec.getSize(r26);
        r8 = android.view.View.MeasureSpec.getMode(r26);
        r9 = android.view.View.MeasureSpec.getSize(r27);
        r10 = android.view.View.MeasureSpec.getMode(r27);
        r0 = r6.g;
        r0.clear();
        r0 = r6.i;
        r0.clear();
        r0 = r6.h;
        r0.clear();
        r11 = r25.getChildCount();
        r0 = r25.getPaddingLeft();
        r0 = r7 - r0;
        r1 = r25.getPaddingRight();
        r12 = r0 - r1;
        if (r8 == 0) goto L_0x003c;
    L_0x0036:
        r0 = r6.a;
        if (r0 == 0) goto L_0x003c;
    L_0x003a:
        r15 = 1;
        goto L_0x003d;
    L_0x003c:
        r15 = 0;
    L_0x003d:
        r0 = r6.b;
        r5 = -65536; // 0xffffffffffff0000 float:NaN double:NaN;
        if (r0 != r5) goto L_0x0047;
    L_0x0043:
        if (r8 != 0) goto L_0x0047;
    L_0x0045:
        r4 = 0;
        goto L_0x0048;
    L_0x0047:
        r4 = r0;
    L_0x0048:
        if (r4 != r5) goto L_0x004c;
    L_0x004a:
        r2 = 0;
        goto L_0x004e;
    L_0x004c:
        r0 = (float) r4;
        r2 = r0;
    L_0x004e:
        r0 = 0;
        r1 = 0;
        r13 = 0;
        r14 = 0;
        r16 = 0;
        r17 = 0;
    L_0x0056:
        if (r1 >= r11) goto L_0x0139;
    L_0x0058:
        r3 = r6.getChildAt(r1);
        r5 = r3.getVisibility();
        r20 = r0;
        r0 = 8;
        if (r5 != r0) goto L_0x007c;
    L_0x0066:
        r0 = r26;
        r5 = r4;
        r21 = r7;
        r23 = r9;
        r18 = r10;
        r22 = r11;
        r3 = r20;
        r7 = -65536; // 0xffffffffffff0000 float:NaN double:NaN;
        r20 = r1;
        r9 = r2;
        r1 = r27;
        goto L_0x0127;
    L_0x007c:
        r5 = r3.getLayoutParams();
        r0 = r5 instanceof android.view.ViewGroup.MarginLayoutParams;
        if (r0 == 0) goto L_0x00bd;
    L_0x0084:
        r21 = 0;
        r22 = r11;
        r11 = r20;
        r0 = r25;
        r20 = r1;
        r1 = r3;
        r23 = r9;
        r9 = r2;
        r2 = r26;
        r18 = r10;
        r10 = r3;
        r3 = r21;
        r24 = r4;
        r4 = r27;
        r19 = r5;
        r21 = r7;
        r7 = -65536; // 0xffffffffffff0000 float:NaN double:NaN;
        r5 = r17;
        r0.measureChildWithMargins(r1, r2, r3, r4, r5);
        r5 = r19;
        r5 = (android.view.ViewGroup.MarginLayoutParams) r5;
        r0 = r5.leftMargin;
        r1 = r5.rightMargin;
        r0 = r0 + r1;
        r1 = r5.topMargin;
        r2 = r5.bottomMargin;
        r1 = r1 + r2;
        r2 = r0;
        r3 = r1;
        r0 = r26;
        r1 = r27;
        goto L_0x00d8;
    L_0x00bd:
        r0 = r26;
        r24 = r4;
        r21 = r7;
        r23 = r9;
        r18 = r10;
        r22 = r11;
        r11 = r20;
        r7 = -65536; // 0xffffffffffff0000 float:NaN double:NaN;
        r20 = r1;
        r9 = r2;
        r10 = r3;
        r1 = r27;
        r6.measureChild(r10, r0, r1);
        r2 = 0;
        r3 = 0;
    L_0x00d8:
        r4 = r10.getMeasuredWidth();
        r4 = r4 + r2;
        r2 = r10.getMeasuredHeight();
        r2 = r2 + r3;
        if (r15 == 0) goto L_0x0117;
    L_0x00e4:
        r3 = r11 + r4;
        if (r3 <= r12) goto L_0x0117;
    L_0x00e8:
        r3 = r6.g;
        r5 = r24;
        r10 = r6.b(r5, r12, r11, r14);
        r10 = java.lang.Float.valueOf(r10);
        r3.add(r10);
        r3 = r6.i;
        r10 = java.lang.Integer.valueOf(r14);
        r3.add(r10);
        r3 = r6.h;
        r10 = java.lang.Integer.valueOf(r16);
        r3.add(r10);
        r3 = r16;
        r17 = r17 + r3;
        r13 = r6.c(r13, r11);
        r3 = (int) r9;
        r3 = r3 + r4;
        r16 = r2;
        r14 = 1;
        goto L_0x0127;
    L_0x0117:
        r3 = r16;
        r5 = r24;
        r14 = r14 + 1;
        r10 = (float) r11;
        r4 = (float) r4;
        r4 = r4 + r9;
        r4 = r4 + r10;
        r4 = (int) r4;
        r16 = r6.c(r3, r2);
        r3 = r4;
    L_0x0127:
        r2 = r20 + 1;
        r1 = r2;
        r0 = r3;
        r4 = r5;
        r2 = r9;
        r10 = r18;
        r7 = r21;
        r11 = r22;
        r9 = r23;
        r5 = -65536; // 0xffffffffffff0000 float:NaN double:NaN;
        goto L_0x0056;
    L_0x0139:
        r11 = r0;
        r5 = r4;
        r21 = r7;
        r23 = r9;
        r18 = r10;
        r3 = r16;
        r7 = -65536; // 0xffffffffffff0000 float:NaN double:NaN;
        r0 = r6.c;
        r1 = -65537; // 0xfffffffffffeffff float:NaN double:NaN;
        if (r0 != r1) goto L_0x0172;
    L_0x014c:
        r0 = r6.g;
        r0 = r0.size();
        r1 = 1;
        if (r0 < r1) goto L_0x0164;
    L_0x0155:
        r0 = r6.g;
        r2 = r0.size();
        r2 = r2 - r1;
        r1 = r0.get(r2);
        r0.add(r1);
        goto L_0x0192;
    L_0x0164:
        r0 = r6.g;
        r1 = r6.b(r5, r12, r11, r14);
        r1 = java.lang.Float.valueOf(r1);
        r0.add(r1);
        goto L_0x0192;
    L_0x0172:
        r1 = -65538; // 0xfffffffffffefffe float:NaN double:NaN;
        if (r0 == r1) goto L_0x0185;
    L_0x0177:
        r1 = r6.g;
        r0 = r6.b(r0, r12, r11, r14);
        r0 = java.lang.Float.valueOf(r0);
        r1.add(r0);
        goto L_0x0192;
    L_0x0185:
        r0 = r6.g;
        r1 = r6.b(r5, r12, r11, r14);
        r1 = java.lang.Float.valueOf(r1);
        r0.add(r1);
    L_0x0192:
        r0 = r6.i;
        r1 = java.lang.Integer.valueOf(r14);
        r0.add(r1);
        r0 = r6.h;
        r1 = java.lang.Integer.valueOf(r3);
        r0.add(r1);
        r17 = r17 + r3;
        r0 = r6.c(r13, r11);
        if (r5 != r7) goto L_0x01af;
    L_0x01ac:
        r1 = r21;
        goto L_0x01cd;
    L_0x01af:
        if (r8 != 0) goto L_0x01be;
    L_0x01b1:
        r1 = r25.getPaddingLeft();
        r1 = r1 + r0;
        r0 = r25.getPaddingRight();
        r0 = r0 + r1;
        r1 = r21;
        goto L_0x01ce;
    L_0x01be:
        r1 = r25.getPaddingLeft();
        r1 = r1 + r0;
        r0 = r25.getPaddingRight();
        r0 = r0 + r1;
        r1 = r21;
        if (r0 >= r1) goto L_0x01cd;
    L_0x01cc:
        goto L_0x01ce;
    L_0x01cd:
        r0 = r1;
    L_0x01ce:
        r2 = r25.getPaddingTop();
        r3 = r25.getPaddingBottom();
        r3 = r3 + r2;
        r3 = r3 + r17;
        r2 = r6.g;
        r2 = r2.size();
        r4 = r6.d;
        r5 = -947912704; // 0xffffffffc7800000 float:-65536.0 double:NaN;
        r7 = (r4 > r5 ? 1 : (r4 == r5 ? 0 : -1));
        if (r7 != 0) goto L_0x01ea;
    L_0x01e7:
        if (r18 != 0) goto L_0x01ea;
    L_0x01e9:
        r4 = 0;
    L_0x01ea:
        r5 = (r4 > r5 ? 1 : (r4 == r5 ? 0 : -1));
        if (r5 != 0) goto L_0x01ff;
    L_0x01ee:
        r5 = 1;
        if (r2 <= r5) goto L_0x01f9;
    L_0x01f1:
        r9 = r23 - r3;
        r2 = r2 - r5;
        r9 = r9 / r2;
        r2 = (float) r9;
        r6.e = r2;
        goto L_0x01fc;
    L_0x01f9:
        r2 = 0;
        r6.e = r2;
    L_0x01fc:
        r3 = r23;
        goto L_0x0211;
    L_0x01ff:
        r5 = 1;
        r6.e = r4;
        r3 = (float) r3;
        r2 = r2 - r5;
        r2 = (float) r2;
        r4 = r4 * r2;
        r4 = r4 + r3;
        r2 = (int) r4;
        r3 = r23;
        if (r18 != 0) goto L_0x020e;
    L_0x020d:
        goto L_0x0212;
    L_0x020e:
        if (r2 >= r3) goto L_0x0211;
    L_0x0210:
        goto L_0x0212;
    L_0x0211:
        r2 = r3;
    L_0x0212:
        r4 = 1073741824; // 0x40000000 float:2.0 double:5.304989477E-315;
        if (r8 != r4) goto L_0x0218;
    L_0x0216:
        r7 = r1;
        goto L_0x0219;
    L_0x0218:
        r7 = r0;
    L_0x0219:
        r0 = r18;
        if (r0 != r4) goto L_0x021f;
    L_0x021d:
        r9 = r3;
        goto L_0x0220;
    L_0x021f:
        r9 = r2;
    L_0x0220:
        r6.setMeasuredDimension(r7, r9);
        return;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.liuzh.deviceinfo.view.togglebuttongroup.FlowLayout.onMeasure(int, int):void");
    }

    public void setChildSpacing(int i) {
        this.b = i;
        requestLayout();
    }

    public void setChildSpacingForLastRow(int i) {
        this.c = i;
        requestLayout();
    }

    public void setFlow(boolean z) {
        this.a = z;
        requestLayout();
    }

    public void setRowSpacing(float f) {
        this.d = f;
        requestLayout();
    }

    public LayoutParams generateLayoutParams(AttributeSet attributeSet) {
        return new MarginLayoutParams(getContext(), attributeSet);
    }
}
